from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout, QHBoxLayout, QLineEdit, QLabel
from projectManager import *


class CreateProcessDialog(QDialog):
    def __init__(self, projectHandle: ProjectManager):
        super().__init__()
        self.setWindowTitle('New Process')
        print("in create dialog")
        self.projectHandle = projectHandle
        btn1 = QPushButton('create', self)
        btn1.clicked.connect(self.create)
        btn2 = QPushButton('close', self)
        btn2.clicked.connect(self.close)
        label = QLabel("Process Name:")
        self.lineEdit = QLineEdit()
        hlayout1 = QHBoxLayout()
        hlayout1.addWidget(label)
        hlayout1.addWidget(self.lineEdit)

        hlayout2 = QHBoxLayout()
        hlayout2.addWidget(btn1)
        hlayout2.addWidget(btn2)

        layout = QVBoxLayout()
        layout.addLayout(hlayout1)
        layout.addLayout(hlayout2)
        self.setLayout(layout)
        self.ret_val = 0

        self.show()

    def getReturnValue(self):
        return self.ret_val

    def create(self):
        self.ret_val = 1
        self.projectHandle.addProcess(self.lineEdit.text())
        self.close()


if __name__ == "__main__":
    import sys

    pm = ProjectManager()
    app = QtWidgets.QApplication(sys.argv)
    ui = CreateProcessDialog(pm)
    ui.show()
    sys.exit(app.exec_())
